﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using EPiServer.Core;

namespace TemplateFoundation.WebControls.PropertyControls
{
    /// <summary>
    /// Property control for PropertyString properties
    /// </summary>
    public class PropertyStringControl : EPiServer.Web.PropertyControls.PropertyStringControl
    {
        /// <summary>
        /// Renders the property control
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            if (RenderType!=RenderType.Default)
            {
                base.Render(writer);
            }
            else
            {
                // Render string without any container element

                var control = Controls[0];

                if (control is HtmlGenericControl)
                {
                    writer.Write(((HtmlGenericControl)control).InnerText);

                    return;
                }

                if (control is Label)
                {
                    writer.Write(((Label)control).Text);

                    return;
                }

                base.Render(writer);
            }
        }
    }
}
